home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Yerk 3.6.6 / Supplement / Unsupported / Utilities / Requires < prev    next >
Encoding:
Text File  |  1985-10-15  |  3.5 KB  |  2 lines  |  [TEXT/MACA]

  1. es
  2. \ A few utility words by Jay Scott, June 1985.
  3. \
  4. \ Original Neon™ code © Copyright 1985 Jay Scott
  5. \ Released October 1985 by Tom O'Brien
  6. \ For free public distribution (not to be sold)
  7. \ provided this notice is kept intact.
  8. \
  9.  
  10. \ In a source file "Source File" put:
  11. \
  12. \     Requires "This File"  \ if the source file needs thisFile loaded first
  13. \     Requires "That File"  \ if the source file needs thatFile loaded first
  14. \     Marker "Source File"  \ declare that "Source File" is loaded
  15. \
  16. \ "This File" (and all other required files) should start with the line
  17. \
  18. \     Marker "This File"
  19. \
  20. \ so that Requires can tell whether it has already been loaded.  Requires will
  21. \ load each file only if it can't find in the dictionary a marker with the
  22. \ same name as the file to be loaded.
  23. \
  24. \ If you reload a file with a marker, Marker will automatically forget
  25. \ the old one.  You can't have two copies of one file loaded at once.
  26. \
  27. \ "This File" and "That File" can require other files.
  28. \ Nesting can't go deeper than six files altogether, counting both
  29. \ // and Requires.
  30. \
  31. \ To explicitly forget a marker, use Forget" .
  32.  
  33.  
  34. \ Expects a search string at HERE & searches all the right vocabularies
  35. \ for it.  The search string can contain blanks and other obnoxious characters.
  36. \ This code is lifted from FIND in the nucleus.
  37. : findHere   ( -- false )               \ if not found
  38.              ( -- pfa lenbyte true )    \ if found
  39.     ufind dup 0= if                 \ what's UFIND? it always leaves 0...
  40.       drop
  41.       here con
  42. p˚text @ (find)         \ look in context vocab
  43.       dup 0= if                     \ if not there,
  44.         context current - if        \ and if current <> context,
  45.           drop here latest (find)   \ look in current vocab
  46.         then
  47.       then
  48.     then
  49.   ;
  50.  
  51.  
  52. : Requires   ( -- ; "fileName" )
  53.     new: loadFile       \ new file on the file stack
  54.     ascii " word                    \ read quoted string from input stream
  55.     here count name: topFile
  56.     findHere if                     \ file is already loaded, do nothing
  57.       2drop
  58.     else                            \ file isn't loaded, announce & load it
  59.       cr ." Requires " here count type
  60.       interpret: loadFile
  61.     then
  62.     remove: loadFile    \ remove the file from the file stack
  63.   ;
  64.  
  65.  
  66. \ Forgets a word, given its PFA.
  67. \ This code is lifted from the original forget.
  68. : (Forget)    ( pfa -- )
  69.     dup fence u< abort" can't forget in protected dictionary"
  70.     dup nfa -> dp
  71.     lfa @ current !
  72.   ;
  73.  
  74.  
  75. \ For forgetting words with spaces in their names, like markers for instance.
  76. : Forget"   ( -- ; "Name" )
  77.     definitions
  78.     ascii " word
  79.     findHere 0= abort" I can't find that word."
  80.     drop (Forget)
  81.   ;
  82.  
  83.  
  84. \ Creates words that may have embedded spaces in their names.
  85. \ It’s to be used to create words with the same names as their files.
  86. \ Also automatically forgets back if there's a word with the same name.
  87. : Marker   { \ oldHere -- ; "Name" }
  88.     definitions
  89.     ascii " word                  \ read "Name" from the input stream
  90.     findHere if                   \ if word already exists,
  91.       here -> oldHere
  92.       cr ." forgetting old version of " here count type
  93.       drop (Forget)               \ forget it
  94.       oldHere c@ here c!          \ make the old name's length correct
  95.     then
  96.     here 1 and if                 \ ensure even word boundary
  97.       0 c,
  98.     then
  99.     $ 80 s,                       \ allot the name field
  100.     latest ,                      \ make a link field
  101.     current !                     \ make it the start of the dictionary
  102.     ' null cfa ,                  \ make a CFA to do nothing
  103.   ;
  104.